// pages/hiddenTrouble/hiddenTrouble.js
import { request } from "../../request/request.js"

const app = getApp()
Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份 
    "d+": this.getDate(), //日 
    "H+": this.getHours(), //小时 
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

Page({

  
  data: {
    employees:'',
    employeesValue:'',
    checkDate: new Date().Format("yyyy-MM-dd"),
    imgList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  ChooseImage() {
    wx.chooseImage({
      count: 4, //默认9
      sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], //从相册选择
      success: (res) => {
        if (this.data.imgList.length != 0) {
          this.setData({
            imgList: this.data.imgList.concat(res.tempFilePaths)
          })
        } else {
          this.setData({
            imgList: res.tempFilePaths
          })
        }
        // console.log(this.data.imgList)
      }
    });
  },
  PickerChange(e) {
    var that=this
    console.log(e);
    this.setData({
      index: e.detail.value,
    })
    that.data.checkCategory= that.data.checkCategory1[e.detail.value]
  },
  DateChange(e) {
    console.log(e);
    this.setData({
      checkDate: e.detail.value
    })
  },
  onLoad: function (options) {
    this.getCheckList(),
    this.getEmployees()
  },

  showRule: function () {
    this.setData({
      isRuleTrue: true
    })
  },
  hideRule: function () {
    this.setData({
      isRuleTrue: false
    })
  },
  selThis(e) {
    this.setData({
      employees: e.detail.label,
      companyCode: e.detail.nodeCode,
      isRuleTrue: false
    })
  },
  async getCheckList(){
    let  token=wx.getStorageSync('token')
    console.log(token)
    const header = {Authorization:token};
    const res= await request({url:'/query_dangerrecord',data:{},header:header});
    console.log(res);
    this.setData({
      unnormalizedValue: res.data.data
    })
  },
  async getEmployees(){
    let  token=wx.getStorageSync('token')
    console.log(token)
    const header = {Authorization:token};
    const res= await request({url:'/employees',data:{},header:header});
    console.log(res.data);
    this.setData({
      employeesValue: res.data.data
    })
  }
})